#include "stdafx.h"
#include "base/Lock.h"

namespace xBase
{
    CxLock::CxLock()
    {
        ::InitializeCriticalSectionAndSpinCount(&m_cs, 2000);
    }

    CxLock::~CxLock()
    {
        ::DeleteCriticalSection(&m_cs);
    }

    VOID CxLock::Acquire()
    {
        ::EnterCriticalSection(&m_cs);
    }

    VOID CxLock::Release()
    {
        ::LeaveCriticalSection(&m_cs);
    }

    BOOL CxLock::Try()
    {
        if (FALSE != ::TryEnterCriticalSection(&m_cs))
        {
            return TRUE;
        }
        else
        {
            return FALSE;
        }
    }
}